Helicopter = Enemy.extend ({

	init: function(context, imagePath, imageHealtBar) {

		this._super(context, imagePath);
		
		this.imageHealtBarH = imageHealtBar;
		this.counter = 0;
		this.numberOfFrame = 5;
		this.frameIndex = 0;
		this.intervalWalk = null;
		this.shootFromEnemy = false;
		
		this.scale =0.50;
		this.curentPositionEnemy = [800, 100];
		this.w = 8;
		this.h = 8;
		this.frame = 0;
		this.frameShootHel = 4;
		this.frameBar=0;
	},
	
	drawWalkEnemy: function(shootToHelicopter) {
		var self = this;
		if((shootToHelicopter %4) ==0 ){
			self.frameBar = shootToHelicopter / 4;
		};
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);		
		this.context.drawImage(self.img, 0, ( self.frame * 121),
								350, 121,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(350 + self.w), ( 121 + self.h));
		
		this.context.drawImage(self.imageHealtBarH, 0, (self.frameBar* 121),
								350, 121,
								(self.curentPositionEnemy[0] + 10), (self.curentPositionEnemy[1]+ 2 + self.h ),
								(330 + self.w),  121);
		this.context.restore();
	},

	drawShooterEnemy: function(shootToHelicopter) {
		var self = this;
		if((shootToHelicopter %4) ==0 ){
			self.frameBar = shootToHelicopter / 4;
		}
		self.frameShootHel = (self.frameShootHel == 4) ? 5 : 4;
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);

		this.context.drawImage(self.img, 0, ( self.frameShootHel * 121),
								350, 121,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(350 + self.w), ( 121 + self.h));
		this.context.drawImage(self.imageHealtBarH, 0, (self.frameBar* 121),
				350, 121,
				(self.curentPositionEnemy[0]+10), (self.curentPositionEnemy[1] + 2 + self.h),
				(330 + self.w), 121);
		this.context.restore();
	},
	
	drawDeadEnemy: function(frameDeadHelicopter) {;
		var self = this;	
		//var frame = self.frameIndex;
		
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);
		this.context.drawImage(self.img, 350, ( frameDeadHelicopter * 121),
								350, 121,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(350 + self.w), ( 121 + self.h));
		this.context.restore();
	},
	
	walkEnemy: function(shootToHelicopter) {
		this.drawWalkEnemy(shootToHelicopter);
		this.curentPositionEnemy[0] += 1;
		this.curentPositionEnemy[1] += 3;
		this.w += 2;
		this.h += 2;
		this.frame = (this.frame == 0) ? 1 : 0;
	},
//	dyingEnemy: function(shoot) {
//		this.shoot = shoot;
//		var self = this;
//		
//		if(this.shoot === 1){
//			self.frameIndex = 0;
//			self.drawDeadEnemy();
//			self.intervalDying = setInterval(function() {
//				
//				if(self.frameIndex < self.numberOfFrame){
//					self.frameIndex++;
//					self.drawDeadEnemy();
//					
//				} else {
//					clearInterval(self.intervalDying);
//					clearInterval(self.intervalWalk);
//					self.clear((self.curentPositionEnemy[0]), (self.curentPositionEnemy[1]));
//				}
//			}, 1000/8);
//		}
//		
//	},
	
	clear: function(x, y) {
		this.context.clearRect((x-10), (y-10), 600, 350);
	},
	
	initEnemy: function(shootToHelicopter) {
		this.walkEnemy(shootToHelicopter);
		
		return [(this.scale * this.curentPositionEnemy[0] - 10), (this.scale * this.curentPositionEnemy[1] - 10), 
		        (this.scale *(this.curentPositionEnemy[0] + 350 + this.w - 50)), (this.scale *(this.curentPositionEnemy[1] + 121 + this.h - 40))];
	}
});